package com.zx.huawei;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by yan.yong2 on 2020/1/9.
 */
public class ListBaoShu {

    public static int inputOut(List list){
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入人数：");
        int n = scanner.nextInt();
        System.out.print("移除位置：");
        int m = scanner.nextInt();

        for(int i=0;i<n;i++){
            list.add(i+1);
        }

        return m;
    }

    public static void remove(List list, int m){
        while(list.size()>1){
            for(int i=0;i<m-1;i++){
                list.add(list.remove(0));//把不是第m个元素重新添加到尾部
            }
            list.remove(0);//移除第m个元素，重新报数
        }
        System.out.print("最后剩下的是："+list.get(0));
    }

    public static void main(String[] args){
        List list = new ArrayList();
        int m = inputOut(list);
        remove(list, m);
    }

}

